package com.softaria.windows.model;

import java.io.Serializable;

/**
 * Sets position of Frame to some percentage of size of its parent panel
 * 
 * @author Roman M Kuzmin (roman@softaria.com)
 * 
 */
public class FloatPositionCalculator implements PositionCalculator, Serializable {

  private static final long serialVersionUID = 1L;
  private float leftFloat;
  private float topFloat;

  public FloatPositionCalculator(float leftFloat, float topFloat) {
    super();
    this.leftFloat = leftFloat;
    this.topFloat = topFloat;
  }

  protected FloatPositionCalculator() {

  }

  public FloatPositionCalculator(double left, double top) {
    this((float) left, (float) top);
  }

  public Position calculatePosition(final int offsetWidth, final int offsetHeight) {
    return new Position() {

      public int getLeft() {
        return (int) (offsetWidth * leftFloat);
      }

      public int getTop() {

        return (int) (offsetHeight * topFloat);
      }

    };
  }

  public float getLeftFloat() {
    return leftFloat;
  }

  public float getTopFloat() {
    return topFloat;
  }

}
